import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

public class Ts220054070558 {
    private String id;
    private String name;
    private String major;
    private int age;

    public Ts220054070558(String id, String name, String major, int age) {
        this.id = id;
        this.name = name;
        this.major = major;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Ts220054070558{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", major='" + major + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection conn = T220054070558.getConn();
        List<Ts220054070558> list = new ArrayList<>();
        Set<Ts220054070558> set = new HashSet<>();
        Map<String,Ts220054070558> map = new HashMap<>();
        String sql = "select * from tzy";
        PreparedStatement psmt = conn.prepareStatement(sql);
        ResultSet rs = psmt.executeQuery();
        while (rs.next()) {
            Ts220054070558 stu = new Ts220054070558(rs.getString(1),
                                                    rs.getString(2),
                                                    rs.getString(3),
                                                    rs.getInt(4));
            list.add(stu);
            set.add(stu);
            map.put(rs.getString(1),stu);
        }

        System.out.println("list:");
        for (Ts220054070558 stu : list) {
            System.out.println(stu);
        }

        System.out.println("set:");
        Iterator<Ts220054070558> iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        System.out.println("map:");
        for (Map.Entry<String, Ts220054070558> entry : map.entrySet()) {
            String key = entry.getKey();
            Ts220054070558 value = entry.getValue();
            System.out.println(key + " was created in " + value);
        }
    }
}
